<template>
  <div class="test-form">
    <parser ref="refParser" :key="currDate" :form-conf="formConf" @submit="sumbitForm" />
  </div>
</template>

<script>

/* eslint-disable */
import Parser from '../Parser'
import { json_data } from './data.js'

export default {  
  components: {
    Parser,
    json_data
  },
  props: {},
  data() {
    return {
      currDate: +new Date(),
      formConf: json_data ,
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    // 表单数据回填，模拟异步请求场景
    setTimeout(() => {
      // 请求回来的表单数据
      const data = {
        mobile: '18836662555',
        userName: '李四'
      }
      // 回填数据
      this.fillFormData(this.formConf, data)
      // 更新表单
      this.currDate = +new Date()
    }, 2000),
    window.getDformVlaue = () => {
      return this.getDformVlaue();
    }
  },
  methods: {
    fillFormData(form, data) {
      form.fields.map(item => {
        const val = data[item.__vModel__]
        if (val) {
          item.__config__.defaultValue = val
        }
        return item
      })
    },
    sumbitForm(data) {
      console.log('sumbitForm1提交数据：', data)
    },
    getDformVlaue() {
      console.log("data");
      var data =  this.$refs['refParser'].getFormModelData();
      console.log(data);
      return data;
    }
  }
}
</script>

<style lang="scss" scoped>
.test-form {
  margin: 15px auto;
  width: 800px;
  padding: 15px;
}
</style>
